package com.huadi.firematerialident.service;

import com.huadi.firematerialident.dao.ReviewDaoImpl;
import com.huadi.firematerialident.po.Admin;
import com.huadi.firematerialident.po.Review;
import com.huadi.firematerialident.po.Reviewer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class ReviewServiceImpl implements ReviewService{
    @Autowired
    ReviewDaoImpl reviewDao;
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    ReviewerServiceImpl reviewerService;

    @Override
    public int addReview(Review review) {
        return reviewDao.addReview(review);
    }

    @Override
    public int deleteReviewByID(String reviewID) {
        return reviewDao.deleteReviewByID(reviewID);
    }

    @Override
    public int updateReview(Review review) {
        return reviewDao.updateReview(review);
    }

    @Override
    public List<Map<String,Object>> selectReviewByID(String reviewID) {
        return reviewDao.selectReviewByID(reviewID);
    }
    //检查review表，不能让同一个鉴定表有多个审查表
    @Override
    public List<Map<String,Object>> selectReviewByID1(String ApsID) {
        return reviewDao.selectReviewByID1(ApsID);
    }


    @Override
    public List<Map<String,Object>> getAllReview() {
        return reviewDao.getAllReview();
    }

    @Override
    public List<Map<String,Object>> getMyReview(){
            String sql="select * from reviewer where RevID=?";
            return jdbcTemplate.queryForList(sql,reviewerService.getRevID());
    }

    @Override
    public Review selectReviewByID_class(String id){
        List<Map<String ,Object>> list = reviewDao.selectReviewByID(id);
        Review review = new Review();
        review.setReviewID((String) list.get(0).get("ReviewID"));
        review.setApsID((String) list.get(0).get("ApsID"));
        review.setRevID((String) list.get(0).get("RevID"));
        review.setRevTime((LocalDateTime) list.get(0).get("RevTime"));
        review.setRevConclusion((String) list.get(0).get("RevConclusion"));  
        review.setArchivingStatus((String) list.get(0).get("ArchivingStatus"));
        review.setLogicalAddDel((boolean) list.get(0).get("LogicalAddDel"));
        review.setLastModification((LocalDateTime) list.get(0).get("LastModification"));
        return review;
    }
}
